import unittest
from time import sleep

from parameterized import parameterized

from page.w_phone_foundation_page import Phone1
from tools.w_read_data import read_data


def get_data1():
    datas = read_data('../data/w_phone_foundation.json')
    print(datas)
    arr = []
    for data in datas.values():
        arr.append((data['phone'], data['announcement'], data['user'], data['expect']))
    return arr


class TestPhone1(unittest.TestCase):
    phone1 = None

    @classmethod
    def setUpClass(cls) -> None:
        cls.phone1 = Phone1()
        cls.phone1.login_admin()

    @classmethod
    def tearDownClass(cls) -> None:
        sleep(3)
        cls.phone1.driver.quit()

    @parameterized.expand(get_data1())
    def test_phone_foundation(self, phone, announcement, user, expect):
        try:
            msg = self.phone1.phone_foundation(phone, announcement, user)
            print('预期结果为：', expect, '实际结果为：', msg)
        except:
            msg = ''
        try:
            self.assertEqual(msg, str(expect))
        except:
            self.phone1.get_image('w')
            raise

    def test_phone_foundation_app(self):
        msg = self.phone1.phone_foundation_app()
        print('预期结果为：', '编辑成功[7]', '实际结果为', msg)
        try:
            self.assertEqual(msg, '编辑成功[7]')
        except:
            self.phone1.get_image('w')
            raise
